home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Apple Shared Library Manager / ASLM Examples / ExampleLibrary / Sources / LibraryManagerTest1.cp < prev    next >
Encoding:
Text File  |  1996-11-19  |  4.0 KB  |  144 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        LibraryManagerTest1.cp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Copyright:    © 1991-1995 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10.  
  11. #ifndef __STDDEF__
  12. #include <stddef.h>
  13. #endif
  14. #ifndef __STDIO__
  15. #include <stdio.h>
  16. #endif
  17. #ifndef __EVENTS__
  18. #include <Events.h>
  19. #endif
  20. #ifndef THINK_CPLUS
  21.     #ifndef __CURSORCTL__
  22.     #include <CursorCtl.h>
  23.     #endif
  24. #endif
  25.  
  26. #ifndef __EXAMPLECLASS__
  27. #include "ExampleClass.h"
  28. #endif
  29.  
  30. static void Idle(RgnHandle);
  31.  
  32. extern "C" 
  33. void DoTests(TExampleClass* object1, TExampleClass* object2, int count, Boolean trace, Boolean verbose, char* testClassInfoClass)
  34. {
  35.     RgnHandle myRgn;
  36.     unsigned long endTicks, startTicks;
  37.     unsigned long saveCount = count;
  38.  
  39.     InitGraf(&qd.thePort);            // initialize quickdraw so we can use regions
  40.     myRgn = NewRgn();                // a region to use for WaitNextEvent
  41.  
  42. #ifndef THINK_CPLUS
  43.     InitCursorCtl(NULL);
  44. #endif
  45.  
  46.     if (object1 && object2) 
  47.     {
  48.         startTicks = TickCount();
  49.         object1->SetObjectName("object1");
  50.         object2->SetObjectName("object2");
  51.         
  52.         while (count-- > 0)                 // <-- here is the test while loop
  53.         {                                    // we put calls to DoThisAndThat in here
  54.             object1->DoThisAndThat();        // here we test DoThisAndThat for object1
  55.             object2->DoThisAndThat();        // here we test DoThisAndThat for object2
  56.             if (trace) Idle(myRgn);            // if we are tracing we must idle
  57. #ifndef THINK_CPLUS
  58.             if (verbose) SpinCursor(1);        // if we are verbose we will spin the cursor
  59. #endif
  60.         }
  61.         
  62.         // test accessing globals
  63.         object1->SetGlobalInt(42);            // set the global using object1
  64.         
  65.         // get the global using object2
  66.         // since object1 and object2 share the same A5 world this will return
  67.         // 42!
  68.         if (verbose)
  69.             printf("%s object2->GetGlobalInt() returns: %d\n",object2->GetObjectName(),object2->GetGlobalInt());
  70.     
  71.         // Test the dynamically linked non-virtual member function GetGlobalRef
  72.         long* theGlobal;
  73.         object1->GetGlobalRef(theGlobal);
  74.         // Now theGlobal is the address of a global variable in the example library, 
  75.         // whose value should still be 42
  76.         if (verbose)
  77.             printf("Address returned by GetGlobalRef is $%x, value is still %d\n", theGlobal, *theGlobal);
  78.         
  79.         endTicks = TickCount();
  80.         if (verbose)
  81.             printf("Dispatches for %d iterations took %d ticks\n", saveCount, endTicks - startTicks);
  82.  
  83.         // Lets try TExampleClass::Test(char*), 
  84.         // note that this is a dynamically linked static member function
  85.         // it will return true since there are 2 instances of TExampleClass
  86.         Boolean hey = TExampleClass::Test("2");
  87.         Boolean hoo = TExampleClass::Test(2);
  88.         Boolean hee = TExampleClass::Test(3);
  89.         if (verbose)
  90.             printf("Three calls to TExampleClass::Test = %s, %s, %s\n",
  91.                 (hey ? "true" : "false"), (hoo ? "true" : "false"), (hee ? "true" : "false"));
  92.     }
  93.  
  94.     if (object1) 
  95.     {
  96.         if (verbose) printf("Disposing object1\n");
  97.         delete object1;
  98.     }
  99.  
  100.     if (object2) {
  101.         if (verbose) printf("Disposing object2\n");
  102.         delete object2;
  103.     }
  104.     
  105.     // Now its time to really do something
  106.     
  107.     if (testClassInfoClass)
  108.     {
  109.         TClassInfo* theInfo = GetLocalLibraryManager()->GetClassInfo(ClassID(testClassInfoClass));
  110.         if (theInfo)
  111.         {
  112.             do
  113.             {
  114.                 char    nameBuffer[256];    // for calls to GetVerboseName
  115.                 printf("\nClass ID:     %s\n", (char*) theInfo->GetClassID());
  116.                 printf("flags:        NewObject(%s) Preload(%s) FunctionSet(%s)\n",
  117.                     theInfo->GetNewObjectFlag() ? "true" : "false",
  118.                     theInfo->GetPreloadFlag() ? "true" : "false",
  119.                     theInfo->GetFunctionSetFlag() ? "true" : "false");
  120.                 printf("version:      Version(%04X) MinVersion(%04X)\n",
  121.                     theInfo->GetVersion(),
  122.                     theInfo->GetMinVersion());
  123.                 if (theInfo->GetLibraryFile())
  124.                     printf("TLibraryFile: %s\n", theInfo->GetLibraryFile()->GetVerboseName(nameBuffer));
  125.                 if (theInfo->GetLibrary())
  126.                     printf("TLibrary:     %s\n", ((TDynamic*)(void*)theInfo->GetLibrary())->GetVerboseName(nameBuffer));
  127.                 if (trace)
  128.                 {
  129.                     Trace("\nClass ID: %s\n", (char*) theInfo->GetClassID());
  130.                 }
  131.             } while (theInfo->Next());
  132.             
  133.             delete theInfo;
  134.         }
  135.     }
  136.     DisposeRgn(myRgn);
  137. }
  138.  
  139. static void Idle(RgnHandle myRgn)
  140. {
  141.     EventRecord myEvent;
  142.     WaitNextEvent(nullEvent, &myEvent, 0, myRgn);
  143. }
  144.